import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/Login.vue";
import Enroll from "../views/Enroll.vue";
import DataShow from "../views/DataShow";

//学生
import StudnetHome from "../views/student/Home.vue";
import InnCenter from "../views/student/InnovateCenter";
import MyInf from "../views/student/MyInf";
import TeamCenter from "../views/student/TeamCenter";
import MyMes from "../views/student/MyMes";
import MyCollect from "../views/student/MyCollect";
import MyTeam from "../views/student/MyTeam";
import Project from "../views/student/Project";
import Team from "../views/student/Team";
import MyTeacher from "../views/student/MyTeacher";
import StudentInf from "../views/student/StudentInf";

//老师
import TeacherHome from "../views/teacher/Home.vue";
import TInnCenter from "../views/teacher/InnovateCenter";
import TMyMes from "../views/teacher/MyMes";
import TProject from "../views/teacher/Project";
import TMyCollect from "../views/teacher/MyCollect";
import TMyInf from "../views/teacher/MyInf";
import TMyStudent from "../views/teacher/MyStudent";
import TStudentInf from "../views/teacher/StudentInf";
import TNewProject from "../views/teacher/NewProject";
//专家
import ExpertHome from "../views/expert/Home.vue";
import EProject from "../views/expert/Project.vue";
import EIntendApplication from "../views/expert/IntendApplication.vue";
import EOverApplication from "../views/expert/OverApplication";
import EMyInf from "../views/expert/MyInf";
//管理员
import AdministratorHome from "../views/administrator/Home.vue";
import AStudents from "../views/administrator/Students.vue";
import ATeachers from "../views/administrator/Teachers.vue";
import AExpert from "../views/administrator/Experts.vue";
import AStudentInf from "../views/administrator/StudentInf";
import ATeacherInf from "../views/administrator/TeacherInf";
import AExpertInf from "../views/administrator/ExpertInf";
import AMyInf from "../views/administrator/MyInf";

Vue.use(VueRouter);
const routes = [
  { path: "/login", name: "login", component: Login },
  { path: "/enroll", name: "Enroll", component: Enroll },
  //学生
  {
    path: "/",
    component: StudnetHome,
    children: [
      { path: "/", redirect: "/DataShow" },
      { path: "/InnCenter", component: InnCenter },
      { path: "/DataShow", component: DataShow },
      { path: "/MyInf", component: MyInf },
      { path: "/TeamCenter", component: TeamCenter },
      { path: "/MyMes", component: MyMes },
      { path: "/MyCollect", component: MyCollect },
      { path: "/MyTeam", component: MyTeam },
      { path: "/Project", component: Project },
      { path: "/Team", component: Team },
      { path: "/MyTeacher", component: MyTeacher },
      { path: "/StudentInf", component: StudentInf },
    ],
  },
  //老师
  {
    path: "/teacher",
    component: TeacherHome,
    children: [
      { path: "/", component: DataShow },
      { path: "tInnCenter", component: TInnCenter },
      { path: "tMyMes", component: TMyMes },
      { path: "tProject", component: TProject },
      { path: "tMyCollect", component: TMyCollect },
      { path: "tMyInf", component: TMyInf },
      { path: "tMyStudent", component: TMyStudent },
      { path: "tStudentInf", component: TStudentInf },
      { path: "tNewPro", component: TNewProject },
    ],
  },
  //专家
  {
    path: "/Expert",
    component: ExpertHome,
    children: [
      { path: "/", component: DataShow },
      { path: "eProject", component: EProject },
      { path: "intendApplication", component: EIntendApplication },
      { path: "overApplication", component: EOverApplication },
      { path: "eMyInf", component: EMyInf },
    ],
  },
  //管理员
  {
    path: "/Administrator",
    component: AdministratorHome,
    children: [
      { path: "/", component: DataShow },
      { path: "student", component: AStudents },
      { path: "teacher", component: ATeachers },
      { path: "expert", component: AExpert },
      { path: "StudentInf", component: AStudentInf },
      { path: "TeacherInf", component: ATeacherInf },
      { path: "ExpertInf", component: AExpertInf },
      { path: "aMyInf", component: AMyInf },

      
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
// 前置路由守卫（路由导航）
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token");
  if (to.path !== "/login") {
    if (to.path !== "/enroll") {
      if (token) {
        next();
      } else {
        alert("请先登录！");
        setTimeout(() => {
          next("/login");
        }, 500);
      }
      return;
    }
  }
  next();
});

export default router;
